﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;

using Microsoft.Practices.Prism.ViewModel;

namespace Finance.UI.ViewModels
{
    public class BatterilyInfoViewModel : NotificationObject
    {
        private const double LowestDisplayPercent = 0.1;

        public double TotalAmount { get; set; }
        public double CanvasHeight { get; set; }

        private double _CurrentAmount;
        public double CurrentAmount
        {
            get
            {
                _CurrentAmount = Math.Min(TotalAmount, _CurrentAmount);
                _CurrentAmount = Math.Max(0, _CurrentAmount);
                return _CurrentAmount;
            }
            set
            {
                _CurrentAmount = Math.Min(TotalAmount, value);
                _CurrentAmount = Math.Max(0, value);
            }
        }

        private double _ActualValueHeigth;
        public double ActualValueHeigth
        {
            get
            {
                _ActualValueHeigth = CanvasHeight * Math.Max(LowestDisplayPercent, CurrentAmount / TotalAmount);
                return _ActualValueHeigth;
            }
        }

        public IDictionary<Color, double> ColorPalette
        {
            private get;
            set;
        }

        private Brush _MixedColor = new SolidColorBrush(Colors.Green);
        public Brush MixedColor
        {
            get
            {
                if (ColorPalette != null)
                {
                    var total = ColorPalette.Values.Sum();
                    double percent = CurrentAmount / TotalAmount;
                    foreach (var item in ColorPalette)
                    {
                        if ((percent = percent - item.Value) < 0)
                        {
                            _MixedColor = new SolidColorBrush(item.Key);
                        }
                    }
                }
                return _MixedColor;
            }
        }
    }
}
